package com.mew.lobby.net;


import com.mew.lobby.message.request.*;
import com.zebra.remoting.config.EmptyMessage;
import com.zebra.remoting.protocol.CommandCode;
import com.zebra.remoting.protocol.CommandType;
import com.zebra.remoting.protocol.PoolType;
import com.zebra.remoting.protocol.ProcessorType;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;


public enum LobbyHandlerMapCmdType implements CommandCode {

    //1000-1010  登录
    LoginLobby(1001, ProcessorType.L_LOGIN, PoolType.EXECUTOR,    EnterLobbyRequestMessage.class), //, "游客登录"
    ReconnectionLobby(1011, ProcessorType.L_RECON,  PoolType.EXECUTOR,   EnterLobbyRequestMessage.class), //重连大厅 需要校验
    SwitchAccount(1012,  EmptyMessage.class),  //切换账号 相当于退出

    //1013开始 用户相关
    UserInfo(1013,   EmptyMessage.class),//用户信息

    //--1100 游戏相关
    GameList(1100,    EmptyMessage.class),
    RoomList(1101,    LoadRoomRequestMessage.class),
    Download(1102,    DownloadGameRequestMessage.class)
//    EnterRoom(1102,    EnterRoomRequestMessage.class), //进房间前检验房间

    ;

    private int cmd ;
    private CommandType commandType;
    private ProcessorType processorType;
    private PoolType poolType;
    private boolean verifyType;
    private final Class request;

    LobbyHandlerMapCmdType(int cmd, ProcessorType processorType, PoolType poolType,   Class request){
        this.cmd = cmd;
        this.processorType = processorType;
        this.poolType = poolType;
        this.verifyType = true;
        this.request = request;
        this.commandType = CommandType.LOBBY;
    }

    LobbyHandlerMapCmdType(int cmd, ProcessorType processorType, Class request){
        this.cmd = cmd;
        this.processorType = processorType;
        this.poolType = PoolType.DISRUPTOR;
        this.verifyType = true;
        this.request = request;
        this.commandType = CommandType.LOBBY;
    }
    
    LobbyHandlerMapCmdType(int cmd,  Class request){
        this.cmd = cmd;
        this.processorType = ProcessorType.GM;
        this.poolType = PoolType.DISRUPTOR;
        this.verifyType = true;
        this.request = request;
        this.commandType = CommandType.LOBBY;
    }

    @Override
    public int cmd() {
        return this.cmd;
    }

    @Override
    public ProcessorType processorType() {
        return this.processorType;
    }

    @Override
    public Class request() {
        return this.request;
    }


    @Override
    public PoolType poolType() {
        return this.poolType;
    }

    @Override
    public boolean verifyType() {
        return this.verifyType;
    }

    @Override
    public CommandType commandType() {
        return this.commandType;
    }

    //转换成 map
    private  static Map<Integer, CommandCode> handlerTypeMap = Arrays.stream(LobbyHandlerMapCmdType.values())
            .collect(Collectors.toMap(LobbyHandlerMapCmdType::cmd, rtype -> rtype));

    public  static LobbyHandlerMapCmdType valueOfCode(int cmd){
        return (LobbyHandlerMapCmdType) handlerTypeMap.get(cmd);
    }

    public  static Map<Integer, CommandCode> getMap(){
        return handlerTypeMap;
    }




}
